﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _11And12PolynomialsOperations
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] polyOne = { 5, 3, 1 };
            int[] polyTwo = { 4, 2, 3 };
            PrIntArray(polyOne);
            Console.WriteLine();
            PrIntArray(polyTwo);
            Console.WriteLine();
            PrIntArray(PolynomialAddition(polyOne, polyTwo));
            Console.WriteLine();
            PrIntArray(PolynomialSubtraction(polyOne, polyTwo));
            Console.WriteLine();
            PrIntArray(PolynomialMultiplication(polyOne, polyTwo));
            Console.WriteLine();
        }
        
        static void PrIntArray(int[] array)
        {
            foreach (var item in array)
            {
                Console.Write("{0,2} ", item);
            }
        }
        
        static int[] PolynomialAddition(int[] first, int[] second)
        { 
            int[] solution = new int[first.Length];
            for (int i = 0; i < first.Length; i++)
            {
                solution[i] = first[i] + second[i];
            }
            return solution;
        }
        
        static int[] PolynomialSubtraction(int[] first, int[] second)
        { 
            int[] solution = new int[first.Length];
            for (int i = 0; i < first.Length; i++)
            {
                solution[i] = first[i] - second[i];
            }
            return solution;
        }
        
        static int[] PolynomialMultiplication(int[] first, int[] second)
        { 
            int[] solution = new int[first.Length*second.Length];
            Array.Reverse(first);
            Array.Reverse(second); //Aligning indexes with powers.
            int k = 0;
            for (int i = 0; i < first.Length; i++)
            {
                for (int j = 0; j < second.Length; j++)
                {
                    solution[k] = first[i] * second[j];
                    k++;
                }
            }
            return solution;
        }
    }
}
